<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/7/12 13:53
 */

namespace App\Project\Printer;

use App\Models\MedicalHpiSub;

class HpiSubPrinter extends PrinterAbstract
{
    public function __construct(MedicalHpiSub $sub)
    {
        $this->model = $sub;
    }

    public function startedAt()
    {
        $print = [
            $this->fe('started_at'),
            $this->fe('inducement', 'value', '诱因:'),
        ];

        if ($symptoms = $this->model->symptoms) {
            $print[] = '出现'.implode('、', $symptoms);
        }

        $print[] = $this->fe('clinic_site', null, '就诊于');

        return $this->getPrintStr('患者于: ', $print);
    }

    public function beforeTreatment()
    {
        $fbg = [
            $this->fe('before_treatment', 'fbg.low'),
            $this->fe('before_treatment', 'fbg.high'),
        ];

        $hpbg = [
            $this->fe('before_treatment', '2hpbg.low'),
            $this->fe('before_treatment', '2hpbg.high'),
        ];

        $print = [];

        if ($fbg[0] && $fbg[1]) {
            $print[] = '空腹血糖:' . implode('-', $fbg) . 'mmol/L';
        }

        if ($hpbg[0] && $hpbg[1]) {
            $print[] = '餐后2h血糖:' . implode('-', $hpbg) . 'mmol/L';
        }

        if ($print) {
            $print[] = $this->fe('before_treatment', 'hba1c', 'HbA1c：', '%');
            return $this->getPrintStr('平时血糖值：', $print);
        }

        return null;
    }

    public function afterTreatment()
    {
        $fbg = [
            $this->fe('after_treatment', 'fbg.low'),
            $this->fe('after_treatment', 'fbg.high'),
        ];

        $hpbg = [
            $this->fe('after_treatment', '2hpbg.low'),
            $this->fe('after_treatment', '2hpbg.high'),
        ];

        $print = [];

        if ($fbg[0] && $fbg[1]) {
            $print[] = '空腹血糖:' . implode('-', $fbg) . 'mmol/L';
        }

        if ($hpbg[0] && $hpbg[1]) {
            $print[] = '餐后2h血糖:' . implode('-', $hpbg) . 'mmol/L';
        }

        if ($print) {
            return $this->getPrintStr('治疗后血糖值：', $print);
        }

        return null;
    }

    public function diagnose()
    {
        $diagnose = $this->model->diagnose;

        if (!$diagnose->count()) {
            return null;
        }

        $print = [
            $diagnose->pluck('name')->implode('、')
        ];

        return $this->getPrintStr('诊断为：', $print);
    }
}